package com.design.YiTong.article.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.design.YiTong.article.service.articleService;
import com.design.YiTong.common.result.Result;
import com.design.YiTong.model.article.articleInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.io.IOException;

@RestController
@RequestMapping("/admin/article")
public class articleController {
    @Autowired
    private articleService articleService;
    @ApiOperation(value = "查询文章")
    @GetMapping("search/{page}")
    public Result searchArticle(@PathVariable Long page){
        Page<articleInfo> pageParam = new Page<>(page, 10);
        IPage<articleInfo>pageModel=articleService.showArticle(pageParam);
        return Result.ok(pageModel);
    }
    @ApiOperation(value = "保存文章")
    @PostMapping("save")
    public Result saveArticle(@RequestBody articleInfo article){
        System.out.println(article.getId());
        //if(article.getId()==null)return Result.fail();
        articleService.saveOrupdataActicle(article);
        return Result.ok();
    }
    @ApiOperation(value = "删除文章")
    @PostMapping("remove/{id}")
    public Result saveArticle(@PathVariable Long id) {
        articleService.removeById(id);
        return Result.ok();
    }
    @ApiOperation(value = "查询文章具体内容")
    @GetMapping("getArticle/{id}")
    public Result getArtcle(@PathVariable Long id){
        articleInfo article=articleService.getActicle(id);
        return Result.ok(article);
    }
}
